package com.ruoyi.web.controller.erp.coordinatorgroup;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.erp.coordinatorgroup.domain.OrderCoordinatorGroupTab;
import com.ruoyi.erp.coordinatorgroup.mapper.CoordinatorGroupMapper;
import com.ruoyi.erp.coordinatorgroup.service.CoordinatorGroupService;
import com.ruoyi.erp.goodpath.domain.DeliveryRouteTab;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/coordinator_group_dao")
@Api(value = "协助查询:")
public class CoordinatorGroupController extends BaseController {
  @Autowired
  private CoordinatorGroupService coordinatorGroupService;
  private String prefix = "erp/coordinatorgroup";
  @RequiresPermissions("coordinatorGroup:coordinatorgroup:view")
  @GetMapping("/list")
  public String list (){
    return prefix+"/list";
  }
  @ApiOperation(value="查询：coordinator_group_dao")
  /**
   * 查询列表
   */
  @RequiresPermissions("coordinatorGroup:coordinatorgroup:list")
  @PostMapping("/select_coordinatorgroup")
  @ResponseBody
  public TableDataInfo getList(OrderCoordinatorGroupTab orderCoordinatorGroupTab){
    List<OrderCoordinatorGroupTab> orderCoordinatorGroupTabList = coordinatorGroupService.getList(orderCoordinatorGroupTab);
    return getDataTable(orderCoordinatorGroupTabList);
  }

  @GetMapping("/add")
  public String add()
  {
    return prefix + "/addList";
  }
  @ApiOperation(value="插入：insert_coordinatorgroup",httpMethod = "POST")
  @RequestMapping("/insert_coordinatorgroup")
  @ResponseBody
  public AjaxResult insertCoordinator(OrderCoordinatorGroupTab orderCoordinatorGroupTab) {
    orderCoordinatorGroupTab.setRowkey(UUID.randomUUID().toString());
    coordinatorGroupService.insertCoordinator(orderCoordinatorGroupTab);
    return AjaxResult.success("添加成功");
  }


  @RequiresPermissions("coordinatorGroup:coordinatorgroup:remove")
  @Log(title = "删除协调人组信息", businessType = BusinessType.DELETE)
  @ApiOperation(value="删除：delete_coordinatorgroup",httpMethod = "POST")
  @PostMapping("/delete_coordinatorgroup")
  @ResponseBody
  public AjaxResult deleteCoordinatorgroups(String ids){
   return toAjax(coordinatorGroupService.deleteCoordinator(ids));
  }

  @RequiresPermissions("coordinatorGroup:coordinatorgroup:edit")
  @ApiOperation(value="更新：update_coordinatorgroup",httpMethod = "POST")
  @ResponseBody
  @PostMapping("/update_coordinatorgroup")
  public AjaxResult updateCoordinatorgoups(OrderCoordinatorGroupTab orderCoordinatorGroupTab) {
    try {
      coordinatorGroupService.updateCoordinator(orderCoordinatorGroupTab);
    } catch (Exception e) {
      e.printStackTrace();
      return AjaxResult.success("修改失败");
    }
    return AjaxResult.success("修改成功");
  }

@Log(title = "协调人组",businessType = BusinessType.EXPORT)
  @RequiresPermissions("coordinatorGroup:coordinatorgroup:export")
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(OrderCoordinatorGroupTab orderCoordinatorGroupTab){
  List<OrderCoordinatorGroupTab> orderCoordinatorGroupTabList = coordinatorGroupService.getList(orderCoordinatorGroupTab);
  ExcelUtil<OrderCoordinatorGroupTab> util = new ExcelUtil<OrderCoordinatorGroupTab>(OrderCoordinatorGroupTab.class);
  return util.exportExcel(orderCoordinatorGroupTabList, "协调人组");
}


  @ApiOperation(value="根据id查询详情")
  @GetMapping("/edit/{id}")
  public String findGoodPath(@PathVariable("id") String authorizeGroup, ModelMap mmap)
  {
    mmap.put("coordinatorGroup", coordinatorGroupService.findOrderCoordinatorGroupTab(authorizeGroup));
    return prefix+"/update";
  }
}
